package easy;

import java.util.ArrayList;
import java.util.List;

public class Solution_1380 {

    public List<Integer> luckyNumbers(int[][] matrix) {
        int[] min_r = new int[matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            int[] ints = matrix[i];
            int min = ints[0];
            for (int j = 1; j < ints.length; j++) {
                if (ints[j] < min) {
                    min = ints[j];
                }
            }
            min_r[i] = min;
        }
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < matrix[0].length; i++) {
            int max_r = 0;
            for (int j = 1; j < matrix.length; j++) {
                if (matrix[j][i] > matrix[max_r][i]) {
                    max_r = j;
                }
            }
            if (matrix[max_r][i] == min_r[max_r]) {
                list.add(min_r[max_r]);
            }
        }
        return list;
    }

    public static void main(String[] args) {
        Solution_1380 model = new Solution_1380();
        System.out.println(model.luckyNumbers(new int[][]{{3, 7, 8}, {9, 11, 13}, {15, 16, 17}}));
        System.out.println(model.luckyNumbers(new int[][]{{1, 10, 4, 2}, {9, 3, 8, 7}, {15, 16, 17, 12}}));
        System.out.println(model.luckyNumbers(new int[][]{{7, 8}, {1, 2}}));
    }
}
